﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Xss.Data.Common.SessionStore
{
    public class WebSessionStore : SessionStore
    {
        public WebSessionStore(string id)
            : base(id)
        { }

        public override IAdoSession CurrentSession
        {
            get
            {
                return (IAdoSession)WebContext.Items[sessionName];
            }
        }

        public override void Store(IAdoSession session)
        {
            WebContext.Items[sessionName] = session;
        }

        public override void Release()
        {
            WebContext.Items.Remove(sessionName);
        }

        private static HttpContext WebContext
        {
            get
            {
                HttpContext httpContext = HttpContext.Current;

                if (httpContext == null)
                {
                    throw new Exception("不能获取 HttpContext 引用");
                }
                return httpContext;
            }
        }
    }
}
